#include "display.h"

int16_t Threshold=0;

int8_t menu=0;
uint8_t mode_old=0;
uint8_t mode=0;
uint8_t BLDC_enble_mode;
uint8_t save=0;
uint8_t save_old=0;

void display()
{
    char buffer[1024];
    memset(buffer,0,sizeof buffer);


//    save=key_get_state(P2);
//    if(save!=save_old)
//    {
//        save_old=save;
//        Write_Flash();
//    }
//    else if(key_get_state(P2)==2)
//    {
//
//    }
    if(key_get_state(P1)==2)
        mode=1;
    else if(key_get_state(P3)==2)
        mode=2;
    else if(key_get_state(P4)==2)
    {
        mode=4;
    }
    else
        mode=0;

    if(mode!=mode_old)
    {
        tft180_clear();
        mode_old=mode;
    }

    switch(mode)
    {
    case 0:
    tft180_show_string(95, 0, "vol");
    tft180_show_float(95, 13, battery.voltage / 1000.0, 2, 1);

    tft180_show_string(6*0,13*5,"en:");tft180_show_int(6*3,13*5,encoder_data_quaddec,5);
    tft180_show_string(6*10,13*5,"Gspeed:");tft180_show_int(6*17,13*5,Gyroscope_Speed,3);

    tft180_show_string(6*0,13*6,"SO:");tft180_show_float(6*3,13*6,Target_Speed.Target_Speed_Out,3,1);
    tft180_show_string(6*11,13*6,"FA:");tft180_show_float(6*14,13*6,Gyroscope.FJ_Angle,3,1);

    tft180_show_string(6*0,13*7,"Err:");tft180_show_float(6*4,13 * 7,Err,3,1);
    tft180_show_string(6*11,13*7,"As:");tft180_show_float(6*14,13*7,Gyroscope.AngleSpeed,2,2);

    tft180_show_string(6*0,13*8,"ea:");tft180_show_int(6*4,13*8,encoder_accu,5);
    tft180_show_string(6*11,13*8,"IsF:");tft180_show_int(6*15,13 * 8,Island.Island_State,1);

    tft180_show_string(6*0,13*9,"SoutL:");tft180_show_int(6*6,13*9,Zebra_Stripes.change_count,4);
    tft180_show_string(6*10,13*9,"SoutR:");tft180_show_int(6*16,13*9,sErr,4);


    tft180_show_string(6*0,13*10,"SSL:");tft180_show_int(6*4,13*10,LonWCol.Search_Stop_Line,4);
    tft180_show_string(6*8,13*10,"TSO:");tft180_show_int(6*12,13*10,Target_Speed.Target_Speed_Out,4);

    tft180_show_gray_image(0, 0, TFT18_Bin_data[0],LCDW, LCDH ,LCDW, LCDH ,Threshold); // 二值化图像到屏幕
    BinRoadSide(); // 显示边界

    break;
    case 1:
    tft180_show_string(6*0,8*0,"STar:");tft180_show_int(6*5,8*0,Target_Speed.Straight_Target_Speed,4);

    tft180_show_string(6*0,8*1,"Ckpp:");tft180_show_float(6*5,8*1,Set_Pid.C_kp,1,1);
    tft180_show_string(6*10,8*1,"Ckdd:");tft180_show_int(6*15,8*1,Set_Pid.C_kd,3);
    tft180_show_string(6*0,8*2,"Ckd:");tft180_show_float(6*5,8*2,Set_Pid.S_kp,1,1);
    tft180_show_string(6*10,8*2,"Ckd:");tft180_show_int(6*15,8*2,Set_Pid.S_kd,3);
    tft180_show_string(6*0,8*3,"Skp:");tft180_show_float(6*5,8*3,Set_Pid.Sp_kp,1,1);
    tft180_show_string(6*10,8*3,"Ski:");tft180_show_float(6*15,8*3,Set_Pid.Sp_ki,1,3);
    tft180_show_string(6*0,8*4,"Ccp:");tft180_show_int(6*5,8*4,Set_Pid.Cc_kp,2);
    tft180_show_string(6*10,8*4,"Ccd:");tft180_show_int(6*15,8*4,Set_Pid.Cc_kd,3);

    tft180_show_string(6*0,8*5,"DTar:");tft180_show_int(6*5,8*5,Target_Speed.Down_Target_Speed,4);



    tft180_show_string(6*0,8*10,"menu:");tft180_show_int(6*5,8*10,menu,2);
    break;
    case 2:
    tft180_displayimage03x((const uint8 *)mt9v03x_image, LCDW, LCDH);
//    tft180_set_dir(TFT180_PORTAIT);
    break;
    }
    system_delay_ms(5);

}
